#include "flag.h"

static struct Structure_flag S_flag;

/***********************************************************************************************************************
*	void SetFlag(uInt8 S_flag)                                                                               *
***********************************************************************************************************************/
void ResetFlag(void){

  uInt8 size;

  size = sizeof(S_flag);

  for( uInt8 loop = 0; loop < size ; loop++ )
  {
    ((uInt8*)&S_flag)[loop] = 0U;
  }


}


/***********************************************************************************************************************
*	void SetFlag(uInt8 S_flag)                                                                               *
***********************************************************************************************************************/
void SetFlag(uInt8 dummy){

  switch (dummy) {

  case FLAG_KEYBOARD:
          S_flag.bKeyboard=1;
  break;

  case FLAG_KEYBOARD_WAIT_FOR_RELEASE:
          S_flag.bKeyboardWaitForRelease=1;
  break;

  case FLAG_KEYBOARD_DISABLE:
          S_flag.bKeyboardDisable=1;
  break;

  case FLAG_ADC_CONVERSION_COMPLETE:
          S_flag.bADC_Complete=1;
  break;

  case FLAG_ADC_CURRENT_MESUREMENT_MODE:
       S_flag.bADC_CurrentMeasurementMode=1;
  break;

  case FLAG_DUMMY1:
          S_flag.bDummy1=1;
  break;

  case FLAG_DUMMY2:
          S_flag.bDummy2=1;
  break;

  case FLAG_DRAW_VOLTAGE:
          S_flag.bDrawVoltage=1;
  break;

  case FLAG_BATT1_PRESENT:
       S_flag.bBatt1_Present=1;
  break;

  case FLAG_BATT2_PRESENT:
       S_flag.bBatt2_Present=1;
  break;

  case FLAG_BATT1_START:
       S_flag.bBatt1_Start=1;
       S_flag.bBatt1_Stop=0;
       S_flag.bBatt1_Low=0;
       S_flag.bBatt1_Fast=0;
       S_flag.bBatt1_Topoff=0;
       S_flag.bBatt1_Trickle=0;
  break;

  case FLAG_BATT1_STOP:
       S_flag.bBatt1_Start=0;
       S_flag.bBatt1_Stop=1;
       S_flag.bBatt1_Low=0;
       S_flag.bBatt1_Fast=0;
       S_flag.bBatt1_Topoff=0;
       S_flag.bBatt1_Trickle=0;
  break;


  case FLAG_BATT1_LOW:
       S_flag.bBatt1_Start=0;
       S_flag.bBatt1_Stop=0;
       S_flag.bBatt1_Low=1;
       S_flag.bBatt1_Fast=0;
       S_flag.bBatt1_Topoff=0;
       S_flag.bBatt1_Trickle=0;
  break;

  case FLAG_BATT1_FAST:
       S_flag.bBatt1_Start=0;
       S_flag.bBatt1_Stop=0;
       S_flag.bBatt1_Low=0;
       S_flag.bBatt1_Fast=1;
       S_flag.bBatt1_Topoff=0;
       S_flag.bBatt1_Trickle=0;
  break;

  case FLAG_BATT1_TOPOFF:
       S_flag.bBatt1_Start=0;
       S_flag.bBatt1_Stop=0;
       S_flag.bBatt1_Low=0;
       S_flag.bBatt1_Fast=0;
       S_flag.bBatt1_Topoff=1;
       S_flag.bBatt1_Trickle=0;
  break;

  case FLAG_BATT1_TRICKLE:
       S_flag.bBatt1_Start=0;
       S_flag.bBatt1_Stop=0;
       S_flag.bBatt1_Low=0;
       S_flag.bBatt1_Fast=0;
       S_flag.bBatt1_Topoff=0;
       S_flag.bBatt1_Trickle=1;
  break;

  case FLAG_BATT2_START:
       S_flag.bBatt2_Start=1;
       S_flag.bBatt2_Stop=0;
       S_flag.bBatt2_Low=0;
       S_flag.bBatt2_Fast=0;
       S_flag.bBatt2_Topoff=0;
       S_flag.bBatt2_Trickle=0;
  break;

  case FLAG_BATT2_STOP:
       S_flag.bBatt2_Start=0;
       S_flag.bBatt2_Stop=1;
       S_flag.bBatt2_Low=0;
       S_flag.bBatt2_Fast=0;
       S_flag.bBatt2_Topoff=0;
       S_flag.bBatt2_Trickle=0;
  break;


  case FLAG_BATT2_LOW:
       S_flag.bBatt2_Start=0;
       S_flag.bBatt2_Stop=0;
       S_flag.bBatt2_Low=1;
       S_flag.bBatt2_Fast=0;
       S_flag.bBatt2_Topoff=0;
       S_flag.bBatt2_Trickle=0;
  break;

  case FLAG_BATT2_FAST:
       S_flag.bBatt2_Start=0;
       S_flag.bBatt2_Stop=0;
       S_flag.bBatt2_Low=0;
       S_flag.bBatt2_Fast=1;
       S_flag.bBatt2_Topoff=0;
       S_flag.bBatt2_Trickle=0;
  break;

  case FLAG_BATT2_TOPOFF:
       S_flag.bBatt2_Start=0;
       S_flag.bBatt2_Stop=0;
       S_flag.bBatt2_Low=0;
       S_flag.bBatt2_Fast=0;
       S_flag.bBatt2_Topoff=1;
       S_flag.bBatt2_Trickle=0;
  break;

  case FLAG_BATT2_TRICKLE:
       S_flag.bBatt2_Start=0;
       S_flag.bBatt2_Stop=0;
       S_flag.bBatt2_Low=0;
       S_flag.bBatt2_Fast=0;
       S_flag.bBatt2_Topoff=0;
       S_flag.bBatt2_Trickle=1;
  break;


  default:
       __no_operation();
  break;

  }

}

/***********************************************************************************************************************
*	ClearFlag(uInt8 S_flag)                                                                             *
***********************************************************************************************************************/
void ClearFlag(uInt8 dummy){

  switch (dummy) {

  case FLAG_KEYBOARD:
          S_flag.bKeyboard=0;
  break;

  case FLAG_KEYBOARD_WAIT_FOR_RELEASE:
          S_flag.bKeyboardWaitForRelease=0;
  break;

  case FLAG_KEYBOARD_DISABLE:
          S_flag.bKeyboardDisable=0;
  break;

  case FLAG_ADC_CONVERSION_COMPLETE:
          S_flag.bADC_Complete=0;
  break;

  case FLAG_ADC_CURRENT_MESUREMENT_MODE:
       S_flag.bADC_CurrentMeasurementMode=0;
  break;

  case FLAG_BATT1_PRESENT:
       S_flag.bBatt1_Present=0;
       S_flag.bBatt1_Start=0;
       S_flag.bBatt1_Stop=0;
       S_flag.bBatt1_Low=0;
       S_flag.bBatt1_Fast=0;
       S_flag.bBatt1_Topoff=0;
       S_flag.bBatt1_Trickle=0;
  break;

  case FLAG_BATT2_PRESENT:
       S_flag.bBatt2_Present=0;
       S_flag.bBatt2_Start=0;
       S_flag.bBatt2_Stop=0;
       S_flag.bBatt2_Low=0;
       S_flag.bBatt2_Fast=0;
       S_flag.bBatt2_Topoff=0;
       S_flag.bBatt2_Trickle=0;
  break;

  case FLAG_DUMMY1:
          S_flag.bDummy1=0;
  break;

  case FLAG_DUMMY2:
          S_flag.bDummy2=0;
  break;

  case FLAG_DRAW_VOLTAGE:
          S_flag.bDrawVoltage=0;
  break;

  default:
       __no_operation();
  break;

  }

}


/***********************************************************************************************************************
*	uInt8 GetFlag(uInt8 S_flag)                                                                            *
***********************************************************************************************************************/
uInt8 GetFlag(uInt8 dummy){

  uInt8 tmp;

  switch (dummy) {

  case FLAG_KEYBOARD:
          tmp = S_flag.bKeyboard;
  break;

  case FLAG_KEYBOARD_WAIT_FOR_RELEASE:
          tmp = S_flag.bKeyboardWaitForRelease;
  break;

  case FLAG_KEYBOARD_DISABLE:
          tmp = S_flag.bKeyboardDisable;
  break;

  case FLAG_ADC_CONVERSION_COMPLETE:
          tmp = S_flag.bADC_Complete;
  break;

  case FLAG_ADC_CURRENT_MESUREMENT_MODE:
       tmp = S_flag.bADC_CurrentMeasurementMode;
  break;

  case FLAG_BATT1_STOP:
       tmp = S_flag.bBatt1_Stop;
  break;

  case FLAG_BATT1_LOW:
       tmp = S_flag.bBatt1_Low;

  break;

  case FLAG_BATT1_FAST:
       tmp = S_flag.bBatt1_Fast;

  break;

  case FLAG_BATT1_TOPOFF:
       tmp = S_flag.bBatt1_Topoff;

  break;

  case FLAG_BATT1_TRICKLE:
       tmp = S_flag.bBatt1_Trickle;
  break;

  case FLAG_BATT2_STOP:
       tmp = S_flag.bBatt2_Stop;
  break;

  case FLAG_BATT2_LOW:
       tmp = S_flag.bBatt2_Low;

  break;

  case FLAG_BATT2_FAST:
       tmp = S_flag.bBatt2_Fast;

  break;

  case FLAG_BATT2_TOPOFF:
       tmp = S_flag.bBatt2_Topoff;

  break;

  case FLAG_BATT2_TRICKLE:
       tmp = S_flag.bBatt2_Trickle;
  break;

  case FLAG_BATT1_PRESENT:
       tmp = S_flag.bBatt1_Present;
  break;

  case FLAG_BATT2_PRESENT:
       tmp = S_flag.bBatt2_Present;
  break;


  case FLAG_DUMMY1:
          tmp = S_flag.bDummy1;
  break;

  case FLAG_DUMMY2:
          tmp = S_flag.bDummy2;
  break;

  case FLAG_DRAW_VOLTAGE:
          tmp = S_flag.bDrawVoltage;
  break;

  default:
       __no_operation();
  break;


  }

    return(tmp);
}

